<template>
  <div>
    <!-- 卡片试图-->
    <el-card>
      <!-- 搜索和添加 -->
      <!-- gutter每列之间的间隔 槽宽 -->
      <el-row :gutter="20">
        <el-col :span="8">
          <el-input placeholder="请输入内容" class="input-with-select">
            <el-button slot="append" icon="el-icon-search"></el-button>
          </el-input>
        </el-col>
        <el-col :span="4">
          <el-button type="primary">添加用户</el-button>
        </el-col>
      </el-row>

      <!-- 用户表格-->
      <!-- 一页有很多行，这个不用关心 会自动帮我们循环 stripe隔行展示 -->
      <el-table :data="userList" border stripe>
          <!-- type="index" 会自动排序 -->
          <el-table-column type="index" label="索引"> </el-table-column>
        <el-table-column prop="username" label="姓名"> </el-table-column>
        <el-table-column prop="email" label="邮箱"> </el-table-column>
        <el-table-column prop="mobile" label="电话"> </el-table-column>
        <el-table-column prop="role_name" label="角色"> </el-table-column>
        <el-table-column label="状态">
          <!--自定义模板 使用作用域插槽,通过scope.row获取当前行数据-->
          <template slot-scope="scope">
            <div>
              <el-switch
                v-model="scope.row.mg_state"
              >
              </el-switch>
            </div>
          </template>
        </el-table-column>
        <el-table-column label="操作">
            <!-- enterable 文字是否可以移入提示信息，默认是可以的 -->
        
      <el-button type="primary" icon="el-icon-edit" size="mini"></el-button>

      <el-button type="danger" icon="el-icon-delete" size="mini"></el-button>
  
         <el-tooltip effect="dark"  placement="top"  content="分配角色" :enterable='false'>
      <el-button type="warning" icon="el-icon-setting" size="mini"></el-button>
    </el-tooltip>
            
            </el-table-column>
      </el-table>
    </el-card>
  </div>
</template>

<script>
export default {
  data() {
    return {
      // 查询用户列表的参数对象
      queryInfo: {
        query: "",
        pagenum: 1, //页码
        pagesize: 5, // 页大小
      },
      // 用户列表数据
      userList: [],
    };
  },

  created() {
    this.getUserList();
  },
  methods: {
    async getUserList() {
      const { data: res } = await this.$http.get("users", {
        params: this.queryInfo,
      });

      if (res.meta.status !== 20000) {
        return this.$message.error("获取失败");
      }
      this.userList = res.data.users;
      console.log(this.userList);
    },
  },
};

</script>

<style lang="scss" scoped>
  .el-table {
    margin-top: 15px;
    font-size: 12px;
}

</style>
